home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / VOXRAY.ZIP / RAY.H < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-12  |  7.7 KB  |  328 lines

  1. #ifndef _RAY_
  2. #define _RAY_
  3. /*********************
  4.  
  5. You can copy or use this file all you like and You will not,
  6. repeat, not be castrated.
  7.  
  8.  
  9. Copyright Matt Howard⌐1995
  10.  
  11.  
  12. *********************/
  13.  
  14. #include "os.h"
  15. #include <stdarg.h>
  16. #include <stddef.h>
  17.  
  18. typedef long MYFIXED;
  19. typedef unsigned char * Ptr;
  20. typedef unsigned char Byte;
  21. typedef struct OBJECT_TYPE * pobject_type;
  22. typedef struct OBJECT_NODE * pobject_node;
  23. typedef struct OBJECT * pobject;
  24. typedef struct VECTOR2 * pvector2;
  25. typedef struct SECTOR * psector;
  26. typedef struct SSECTOR * pssector;
  27. typedef struct SIDEDEF * psidedef;
  28. typedef short ptexture;
  29. typedef struct LINEDEF * plinedef;
  30. typedef struct RECTANGLE * prectl;
  31. typedef struct SEG * pseg;
  32. typedef long angle_type;
  33. typedef void * pdata;
  34. typedef SHORT render_type;
  35. typedef void (* update_func)(pobject cur_obj, long update_num);
  36. typedef void (* update_z_func)(pobject cur_obj, psector new_sec);
  37. typedef void (* load_extra_func)(pobject cur_obj, long offset);
  38. typedef void (* render_func)(pobject cur_sprite);
  39. typedef void (* render_data_loader)(pobject_type cur_type, long offset);
  40. typedef ULONG (* message_func)(pobject send_obj, pobject receive_obj,
  41.           ULONG message, pdata extra_data);
  42. typedef update_func * pupdate_func;
  43. typedef load_extra_func * pload_extra_func;
  44. typedef update_z_func * pupdate_z_func;
  45. typedef render_func * prender_func;
  46. typedef render_data_loader * prender_data_loader;
  47. typedef message_func * pmessage_func;
  48. typedef struct OBJ_STATS * pstats;
  49. typedef struct CUR_STATS * pcur_stats;
  50.  
  51. typedef struct RECTANGLE {
  52.     long left, right, top, bottom;
  53. } rectangle;
  54.  
  55. typedef struct OBJ_STATS {
  56.     short total_health;
  57.     short base_speed;
  58.     long sight_dis;
  59.     pdata other_stats;
  60. } obj_stats;
  61.  
  62. typedef struct OBJECT_TYPE {
  63.           obj_stats stats;
  64.           ULONG obj_class;
  65.     ptexture * frames;
  66.           BOOL * rev_frames;
  67.     USHORT angle_num;
  68.     angle_type half_angle;
  69.     USHORT width, height;
  70.     USHORT wh_ratio, wshift, hshift;
  71.           USHORT eye_height, stepping_height;
  72.           MYFIXED block_width, obj_width;
  73.     update_z_func Update_Z;
  74.     load_extra_func Load_Extra;
  75.     update_func Update;
  76.           render_func Render_Func;
  77.           render_data_loader Render_Data_Loader;
  78.           message_func Message_Func;
  79.           pdata render_data;
  80.           pdata extra_data;
  81.     /*
  82.     more attributes here
  83.     */
  84. } object_type;
  85.  
  86. typedef struct OBJECT_NODE {
  87.     pobject_node front, back;
  88.     pobject data;
  89. } object_node;
  90.  
  91. typedef struct CUR_STATS {
  92.     short current_health;
  93.     MYFIXED current_speed;
  94.     } cur_stats;
  95.  
  96. typedef struct OBJECT {
  97. cur_stats stats;
  98. long    x,y,z;
  99. long tx, ty;
  100. USHORT team;
  101. pobject owner;
  102. PUSHORT texture_indexes;
  103. psector cur_sec;
  104. pssector cur_ss;
  105. pobject_node ss_node, global_node, send_objects, receive_objects, block_node;
  106. USHORT block_x, block_y;
  107. pobject_type type;
  108. USHORT cur_frame;
  109. long angle;
  110. /*
  111.   more attributes here
  112. */
  113. pdata extra_data;
  114. } object;
  115.  
  116. typedef short tex_mark;
  117.  
  118. typedef struct VECTOR2 {
  119.     LONG x, y;
  120.     } vector2;
  121.  
  122. typedef struct SIDEDEF {
  123.     USHORT attributes;
  124.     SHORT x_offset, y_offset;
  125.     ptexture texture_normal, texture_low, texture_high;
  126.     psector sec;
  127.     } sidedef;
  128.  
  129. typedef struct LINEDEF {
  130.     short v[2];
  131.     psidedef s[2];
  132.     USHORT tag;
  133.     USHORT tag_type;
  134.     USHORT attributes;
  135.           MYFIXED distance;
  136.     } linedef;
  137.  
  138. typedef struct SECTOR {
  139.     USHORT tag;
  140.     SHORT floor_height, ceil_height;
  141.     ptexture floor_tex, ceil_tex;
  142.     UCHAR light;
  143.           USHORT flags;
  144.           pdata extra_data;
  145.     } sector;
  146.  
  147. typedef struct SEG {
  148.     short v[2];
  149.     LONG angle;
  150.     plinedef ld;
  151.     BOOL left_sidedef;
  152.     LONG linedef_offset;
  153.     } seg;
  154.  
  155. typedef struct SSECTOR {
  156.     SHORT seg_start;
  157.     SHORT seg_end;
  158.     USHORT num_objects;
  159.     pobject_node objects;
  160.           USHORT flags;
  161.           pdata   extra_data;
  162.     
  163. } ssector;
  164.  
  165. typedef struct BSP_NODE {
  166.     long x1, x2, y1, y2;
  167.     rectangle left_bound, right_bound;
  168.     USHORT left_child, right_child;
  169. } bsp_node;
  170.  
  171. typedef struct WALL_ENTRY {
  172.     short num_image, cur_image;
  173.     long anim_speed, anim_sum;
  174.           short width, height;
  175.           Byte shift;
  176.     Byte ** images;
  177. } wall_entry;
  178.  
  179. void    initRay();
  180. void    closeRay();
  181. void Render_Screen(long x, long y, long z, long view_angle);
  182. void Render_Init();
  183. void Render_Close();
  184. void SwitchRenderMode();
  185. render_type GetRenderMode();
  186. void Map_Scale_Increase();
  187. void Map_Scale_Decrease();
  188. void SetRenderMode(render_type mode);
  189. void Build_Tables(void);
  190. void Build_Height_Table(void);
  191. void Build_Vertical_Distance_Table();
  192. void setWindowDimensions(short height);
  193. void setWindowFOV(short vertangle);
  194. void setupNewScreen();
  195. void View_Angle_Up();
  196. void View_Angle_Down();
  197. void Set_View_Angle(angle_type angle);
  198. angle_type Get_Vert_View_Angle();
  199. void Setup_Anim_Tex();
  200. void Animate_Textures(long update_num);
  201.  
  202. void F_Init();
  203. void F_Scan_Load(char * filename);
  204. void F_Spec_Load(short num_elements, char * filename, ... );
  205. void F_Doom_Load(char * filename);
  206. void F_Shutdown();
  207.  
  208. #define TEXTURE_NULL -1
  209.  
  210. #define MODE_3D 0
  211. #define MODE_2D 1
  212.  
  213.  
  214. #define STEP_LENGTH 15       // number of units player moves foward or backward
  215.  
  216. #define OVERBOARD       52  // the closest a player can get to a wall
  217.  
  218. #define WORLD_ROWS    64     // number of rows in the game world
  219. #define WORLD_COLUMNS 64     // number of columns in the game world
  220.  
  221. #define CELL_X_SIZE   64     // size of a cell in the gamw world
  222. #define CELL_Y_SIZE   64
  223.  
  224.  
  225. #define CELL_X_SIZE_FP   6   // log base 2 of 64 (used for quick division)
  226. #define CELL_Y_SIZE_FP   6
  227.  
  228. #define WORLD_X_SIZE  (WORLD_COLUMNS * CELL_X_SIZE)
  229. #define WORLD_Y_SIZE  (WORLD_ROWS    * CELL_Y_SIZE)
  230. #define ANGLE_0     0
  231. #define ANGLE_1     5
  232. #define ANGLE_2     10
  233. #define ANGLE_3     16
  234. #define ANGLE_4     20
  235. #define ANGLE_5     25
  236. #define ANGLE_6     32
  237. #define ANGLE_12    60
  238. #define ANGLE_15    80
  239. #define ANGLE_30    160
  240. #define ANGLE_45    240
  241. #define ANGLE_60    320
  242. #define ANGLE_90    480
  243. #define ANGLE_135   720
  244. #define ANGLE_180   960
  245. #define ANGLE_225   1200
  246. #define ANGLE_270   1440
  247. #define ANGLE_315   1680
  248. #define ANGLE_330   1760
  249. #define ANGLE_360   1920     // note: the circle has been broken up into 1920
  250.                   // sub-arcs
  251. #define INTERSECTION_FOUND      1
  252. #define WEIRD2RAD       (6.283185307/1920)
  253. #define MAX_SCALE             500  // maximum size and wall "sliver" can be 201
  254.  
  255. #define MAX_WINDOW_HEIGHT 480 // don't let window height beyond this
  256. #define MIN_WINDOW_HEIGHT 20 // and done let the height fall below this
  257. #define MAX_VERT_FOV ANGLE_90
  258. #define MIN_VERT_FOV ANGLE_15
  259.  
  260. #define MAX_LIGHT 0xf
  261. #define MAX_SECTOR_LIGHT 0xff
  262. #define SEC_LIGHT_MASK 0x0f
  263. #define SEC_LTSPEED_MASK 0xf0
  264. #define SEC_LTSPEED_SHIFT 4
  265.  
  266. #define SLIVER_SHIFT 20
  267. #define SLIVER_ONE 1048576
  268.  
  269. #define X_TRANS_SHIFT 6
  270.  
  271. #define SHIFT 14
  272. #define SHIFTLESS 13
  273. #define DOUBLE_SHIFT    18
  274. #define ONE     16384
  275. #define CELL_SIZE_SHIFT_FP      20      //CELL_X_SIZE_FP+SHIFT
  276. #define OTHERSHIFT              4
  277. #define OONE                    16
  278.  
  279. #define MAXDIS 5793
  280.  
  281. #define W_TEX_SHIFT 0
  282.  
  283. #define Z_MOVE_MAX 8
  284. #define Z_ANGLE_DELTA ANGLE_15
  285. #define Z_ANGLE_INC ANGLE_15
  286.  
  287. #define F_NAME_LENGTH 100
  288. #define BOOL_NAME_LENGTH 6
  289. #define MAX(a,b) ( (a) > (b) ? (a) : (b) )
  290. #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
  291.  
  292. #define VOXEL_SSECTOR   1
  293. #define VOXEL_SECTOR 1
  294. #define TWO_SIDED_SD 4
  295.  
  296. #ifdef __cplusplus
  297.  
  298. #include "memutil.h"
  299.  
  300. inline long Get_Angle_Difference(long angle1, long angle2)
  301. {
  302.      long temp_angle=angle1-angle2;
  303.      if (temp_angle<0) {
  304.             temp_angle+=ANGLE_360;
  305.      }
  306.      return temp_angle;
  307. }
  308.  
  309. inline long Get_Angle_Sum(long angle1, long angle2)
  310. {
  311.      long temp_angle=angle1+angle2;
  312.      if (temp_angle>=ANGLE_360)
  313.             temp_angle-=ANGLE_360;
  314.      return temp_angle;
  315. }
  316.  
  317. #ifdef OS_DOS
  318. inline BOOL operator ! (BOOL the_bool)
  319. {
  320.   return ((the_bool==TRUE) ? FALSE : TRUE);
  321. }
  322. #endif
  323.  
  324. #endif
  325. // End of IBM stuff
  326.  
  327. #endif
  328.